
EnableExplicit
XIncludeFile "mathutils.pb"

Procedure Math_Example1(); Matrix multiplication
	Protected.mat3 A, B, C, D
	Mat3_SetL1(A, 2, -1, -3)
	Mat3_SetL2(A, 8, -7, -6)
	Mat3_SetL3(A, -3, 4, 2)
	
	Mat3_SetL1(B, 2, -1, -2)
	Mat3_SetL2(B, 3, -4, 4)
	Mat3_SetL3(B, 1, 2, 1)
	
	Mat3_MulM(C, A, B)
	Mat3_Debug(C)
	Debug ""
	Mat3_MulM(D, B, A)
	Mat3_Debug(D)
EndProcedure
Procedure Math_Example2(); Building basis matrix
	Protected.mat3 Basis
	Protected.mat4 B4
	Protected.vec3 i, j, k
	Protected.vec4 l
	Vec3_Set(i, 1, 0, 0)
	Vec3_Set(j, 0, 1, 0)
	Vec3_Set(k, 0, 0, 1)
	Mat3_SetV(Basis, i, j, k)
	;Vec4_Set(l, 0, 0, 0, 1)
	;Mat4_SetM(B4, Basis, l)
	;Mat4_Debug(B4)
EndProcedure
Procedure Math_Example3(); Building perspective matrx
	Protected.mat4 P
	Mat4_Perspective(P, #PI/4, 1, 1/10, 100)
	Mat4_Debug(P)
EndProcedure
Procedure Math_Example4(); Building matrx from quaternion and vector
	Protected.vec4 qRot, vPos
	Protected.mat3 mRot
	Protected.mat4 modelview
	; input - qRot, vPos
	Mat3_FromQuat(mRot, qRot)
	Mat4_SetM(modelview, mRot, vPos)
EndProcedure
Procedure Math_Example5(); Quaternion operations
	Protected.vec3 vAxe, pos
	Protected.vec4 qAxeY, qAxeZ, qAxeYZ
	Vec3_Set(vAxe, 0, 1, 0)
	Quat_FromAxis(qAxeY, vAxe, Radian(90))
	Vec3_Set(vAxe, 0, 0, 1)
	Quat_FromAxis(qAxeZ, vAxe, Radian(90))
	Quat_MulQ(qAxeYZ, qAxeY, qAxeZ)
	Vec4_Debug(qAxeYZ)
	Vec3_Set(pos, 0, 0, 1)
	;Quat_MulV(pos, qAxeYZ, pos)
	;Vec3_Debug(pos)
EndProcedure
Procedure Math_Example6(); Quaternion operations test2
	Protected.vec3 vAxe, pos, pos_r
	Protected.vec4 qAxe
	Vec3_Set(vAxe, 0, 0, 1)
	Vec3_Normalize(vAxe)
	Quat_FromAxis(qAxe, vAxe, Radian(90))
	Vec4_Debug(qAxe)
	Vec3_Set(pos, 1, 0, 0)
	Quat_MulV_Setup(qAxe)
	Quat_MulV(pos_r, pos)
	Vec3_Debug(pos_r)
	Debug "len pos = " + Vec3_Len(pos_r)
EndProcedure
Procedure Math_Example7(); Quaternion operations test3
	Protected.vec3 vAxe, pos
	Protected.vec4 qAxe
	Protected.mat3 M
	Vec3_Set(vAxe, 0, 0, 1)
	Quat_FromAxis(qAxe, vAxe, Radian(90))
	Vec4_Debug(qAxe)
	Vec3_Set(pos, 0, 0, 1)
	Mat3_FromQuat(M, qAxe)
	Mat3_MulV(pos, M, pos)
	;Vec3_Debug(pos)
EndProcedure
Procedure Math_Example8(); Quaternion operations test correcting
	Protected.vec3 vAxe1, vAxe2, pos, _pos, __pos
	Protected.vec4 q1, q2, q1q2
	Vec3_Random(vAxe1) : Vec3_Normalize(vAxe1)
	Vec3_Random(vAxe2) : Vec3_Normalize(vAxe2)
	Vec3_Debug(vAxe1) : Vec3_Debug(vAxe2)
	Quat_FromAxis(q1, vAxe1, Real_Random(-180, 180))
	Quat_FromAxis(q2, vAxe2, Real_Random(-180, 180))
	Vec3_Random(pos)
	Vec3_Debug(pos)
	Quat_MulQ(q1q2, q1, q2)
	Quat_MulV_Setup(q1q2)
	Quat_MulV(_pos, pos)
	Vec3_Debug(_pos)
	Quat_MulV_Setup(q1)
	Quat_MulV(_pos, pos)
	Quat_DivV_Setup(q1)
	Quat_DivV(__pos, _pos)
	Vec3_Debug(__pos)
EndProcedure
Math_Example8()
















; IDE Options = PureBasic 5.11 (Windows - x86)
; CursorPosition = 100
; FirstLine = 2
; Folding = A+
; EnableXP